package solutions.leetcode.easy;

import solutions.lib.ListNode;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/merge-two-sorted-lists/">21. 合并两个有序链表</a>
 */
public class Solution21 {

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode rst = new ListNode();
        ListNode p = rst;

        while (l1 != null || l2 != null) {
            int v1 = l1 == null ? 101 : l1.val;
            int v2 = l2 == null ? 101 : l2.val;
            System.out.println(v1 + ", " + v2);
            if (v1 < v2) {
                p.next = l1;
                l1 = l1.next;
            } else {
                p.next = l2;
                l2 = l2.next;
            }
            p = p.next;
        }

        return rst.next;
    }

    public static void main(String[] args) {
        Solution21 solution = new Solution21();
    }
}
